package com.mf.pte;

import com.mf.pte.core.AssemblyProcessSystem;
import com.mf.pte.selection.NestedDisplay;
import com.mf.pte.selection.NestedHighlight;
import com.mf.pte.selection.NestedUnhighlight;
import com.mf.pte.utils.BomExportUtil;
import com.ptc.cipjava.jxthrowable;
import com.ptc.pfc.pfcCommand.UICommand;
import com.ptc.pfc.pfcExceptions.XToolkitFound;
import com.ptc.pfc.pfcSession.CreoCompatibility;
import com.ptc.pfc.pfcSession.Session;
import com.ptc.pfc.pfcSession.pfcSession;
import com.ptc.wfc.wfcSession.WSession;

public class EntryPoint {

    private Session session;
    private WSession wSession;

//    private static final String ribbonFile = "otkJavaExamples.rbn";
    private static final String msgFile = "technique.txt";

    public EntryPoint() throws jxthrowable {
        addAllCommand();
    }

    public static void start() throws jxthrowable {
        new EntryPoint();
    }

    public static void stop(){}

    public void addAllCommand() throws jxthrowable {
        try
        {
            session = pfcSession.GetCurrentSessionWithCompatibility (CreoCompatibility.C4Compatible);
            wSession = (WSession)session;
            addBomExportCommand();
            addBomExportCommand1();
            addBomExportCommand2();
            addBomExportCommand3();

        }catch (XToolkitFound x){
            System.out.println("问题消息="+x.GetMessage());
            System.out.println("方法名="+x.GetMethodName());
            System.out.println("原生方法名="+x.GetToolkitFunctionName());
            System.out.println("错误代码="+x.GetErrorCode());
        }
        catch (Throwable e)
        {
            System.out.println ("Exception caught: "+e);
            e.printStackTrace ();
        }

    }

    private void addBomExportCommand() throws jxthrowable {
        UICommand cmd;
        String fileName = "bom_test.txt";
        cmd = wSession.UICreateCommand("command0", new BomExportUtil(wSession,fileName) );
        cmd.Designate(msgFile, "bom exporter", "bom exporter", "bom exporter");
    }

    private void addBomExportCommand1() throws jxthrowable {
        UICommand cmd;
        cmd = wSession.UICreateCommand("command1", new NestedDisplay(session,wSession) );
        cmd.Designate(msgFile, "NestedDisplay","NestedDisplay","NestedDisplay");
    }
    private void addBomExportCommand2() throws jxthrowable {
        UICommand cmd;
        cmd = wSession.UICreateCommand("command2", new NestedHighlight(session,wSession));
        cmd.Designate(msgFile, "NestedHighlight","NestedHighlight","NestedHighlight");
    }
    private void addBomExportCommand3() throws jxthrowable {
        UICommand cmd;
        cmd = wSession.UICreateCommand("command3", new NestedUnhighlight(session,wSession));
        cmd.Designate(msgFile, "NestedUnhighlight","NestedUnhighlight","NestedUnhighlight");
    }
}
